package com.shw.pclient.adapter;

import java.util.List;

import com.shw.pclient.R;
import com.shw.pclient.vo.HomeInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 
 * @author HAHA
 *
 */
public class SHWHomeAdapter extends BaseAdapter {

	private class GridHolder {
		ImageView imageView;
		TextView textView;
	}

	private Context context;
	private List<HomeInfo> homeInfos;
	private LayoutInflater layoutInflater;

	public SHWHomeAdapter(Context context) {
		super();
		this.context = context;
	}

	public void setList(List<HomeInfo> homeInfos) {
		this.homeInfos = homeInfos;
		layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return homeInfos.size();
	}

	@Override
	public Object getItem(int arg0) {

		return homeInfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		GridHolder gridHolder;
		if (arg1 == null) {
			arg1 = layoutInflater.inflate(R.layout.home_item, null);
			gridHolder = new GridHolder();
			gridHolder.imageView=(ImageView) arg1.findViewById(R.id.ItemImage);
			gridHolder.textView=(TextView) arg1.findViewById(R.id.ItemText);
			arg1.setTag(gridHolder);
		}else{
			gridHolder=(GridHolder) arg1.getTag();
		}
		HomeInfo homeInfo = homeInfos.get(arg0);
		if(homeInfo != null){
			gridHolder.textView.setText(homeInfo.getName());
			gridHolder.imageView.setImageResource(homeInfo.getImgPath());
		}
		return arg1;
	}

}
